package com.noble.glamour.bean.config.base;

import com.noble.library.base.bean.BaseData;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * config/GetSet#nobility_config#nobility_titles节点，爵位配表
 * Created by ZRP on 2017/7/19.
 */

public class NobilityList extends BaseData {

    private List<Nobility> nobilityList;

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);
        nobilityList = (List<Nobility>) getBaseDataList(jsonObject.optJSONArray("nobility_titles"), Nobility.class);
    }

    /**
     * 根据爵位id获取当前爵位的信息
     *
     * @param id 爵位id
     * @return 当前爵位的信息
     */
    public Nobility queryNobility(int id) {
        if (nobilityList == null || nobilityList.isEmpty()) {
            return new NobilityList.Nobility();
        }
        // 兼容越界查询，返回最高级别爵位信息
        if (id >= nobilityList.size()) id = nobilityList.size() - 1;
        for (Nobility temp : nobilityList) {
            if (id == temp.getId()) return temp;
        }
        return new Nobility();
    }

    public List<Nobility> getNobilityList() {
        return nobilityList == null ? new ArrayList<Nobility>() : nobilityList;
    }

    @Override
    public String toString() {
        return "NobilityList{" +
                "nobilityList=" + nobilityList +
                '}';
    }

    /**
     * 爵位信息
     */
    public static class Nobility extends BaseData {

        private int id;
        private String name;            //爵位名称

        private double audio_discount;  //语音打折
        private double video_discount;  //视频打折

        private String car_name;        //座驾名称
        private String car_pic;         //座驾图片

        private int keep_condition;     //维持条件
        private int upgrade_condition;  //升级条件

        private String main_page_bg;    //主页背景
        private String list_bg;         //列表背景

        private String title_badge_big; //爵位大勋章，用于升级全屏显示
        private String title_badge_small;//爵位小勋章，名字后面显示
        private String title_icon;      //爵位标记，名字后面显示
        private String title_name_pic;  //爵位名图片，用于升级全屏显示

        @Override
        public void parseJson(String jsonStr) {
            JSONObject jsonObject = getJsonObject(jsonStr);
            id = jsonObject.optInt("id");
            name = jsonObject.optString("name");

            audio_discount = jsonObject.optDouble("audio_discount");
            video_discount = jsonObject.optDouble("video_discount");

            car_name = jsonObject.optString("car_name");
            car_pic = jsonObject.optString("car_pic");

            keep_condition = jsonObject.optInt("keep_condition");
            upgrade_condition = jsonObject.optInt("upgrade_condition");

            main_page_bg = jsonObject.optString("main_page_bg");
            list_bg = jsonObject.optString("list_bg");

            title_badge_big = jsonObject.optString("title_badge_big");
            title_badge_small = jsonObject.optString("title_badge_small");
            title_icon = jsonObject.optString("title_icon");
            title_name_pic = jsonObject.optString("title_name_pic");
        }

        public int getId() {
            return id;
        }

        public String getName() {
            return name;
        }

        public double getAudio_discount() {
            return audio_discount;
        }

        public double getVideo_discount() {
            return video_discount;
        }

        public String getCar_name() {
            return car_name;
        }

        public String getCar_pic() {
            return car_pic;
        }

        public int getKeep_condition() {
            return keep_condition;
        }

        public int getUpgrade_condition() {
            return upgrade_condition;
        }

        public String getMain_page_bg() {
            return main_page_bg;
        }

        public String getList_bg() {
            return list_bg;
        }

        public String getTitle_badge_big() {
            return title_badge_big;
        }

        public String getTitle_badge_small() {
            return title_badge_small;
        }

        public String getTitle_icon() {
            return title_icon;
        }

        public String getTitle_name_pic() {
            return title_name_pic;
        }

        @Override
        public String toString() {
            return "Nobility{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", audio_discount=" + audio_discount +
                    ", video_discount=" + video_discount +
                    ", car_name='" + car_name + '\'' +
                    ", car_pic='" + car_pic + '\'' +
                    ", keep_condition=" + keep_condition +
                    ", upgrade_condition=" + upgrade_condition +
                    ", main_page_bg='" + main_page_bg + '\'' +
                    ", list_bg='" + list_bg + '\'' +
                    ", title_badge_big='" + title_badge_big + '\'' +
                    ", title_badge_small='" + title_badge_small + '\'' +
                    ", title_icon='" + title_icon + '\'' +
                    ", title_name_pic='" + title_name_pic + '\'' +
                    '}';
        }
    }
}
